package br.com.news.service;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import br.com.news.utils.business.exception.BusinessException;
import br.com.news.utils.business.interfaces.IEnqueteBusiness;
import br.com.news.utils.database.beans.EnqueteBean;
import br.com.news.utils.service.exception.ServiceException;
import br.com.news.utils.service.interfaces.IEnqueteService;

@Named
public class EnqueteService implements IEnqueteService{
	
	@Inject
	private IEnqueteBusiness enqueteBusiness;

	@Override
	public Long save(EnqueteBean enquete) throws ServiceException {
		try {
			return enqueteBusiness.save(enquete);
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}
	
	@Override
	public void update(EnqueteBean enquete) throws ServiceException {
		try {
			enqueteBusiness.update(enquete);
		} catch (BusinessException e) {
			throw new ServiceException("Erro ao tentar fazer update na enquete, camada service.",e);
		}	
	}
	
	@Override
	public List<EnqueteBean> findByQuestion(EnqueteBean questao) {
		return enqueteBusiness.findByQuestion(questao);
	}

	@Override
	public List<EnqueteBean> findPollByStatus(boolean status) throws ServiceException {
		try {
			return enqueteBusiness.findPollByStatus(status);
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}
	
	@Override
	public List<EnqueteBean> findPollActive() throws ServiceException {
		try {
			return enqueteBusiness.findPollActive();
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}
	
	@Override
	public List<EnqueteBean> findAll() throws ServiceException{
		try {
			return enqueteBusiness.findAll();
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}

	@Override
	public List<EnqueteBean> lastPoll() throws ServiceException {
		try {
			return enqueteBusiness.lastPoll();
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}
	
}
